package com.zqg8512.netty.reponse;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * @Author zengqianggang
 * @Description //TODO
 * Author VPN
 * @Date 2019/9/30 10:05
 * @Version 1.0
 **/
public class NettyServer {

    public static void main(String[] args) throws InterruptedException {
        new NettyServer().start();
    }
    public void start() throws InterruptedException {

        EventLoopGroup boos = new NioEventLoopGroup();
        EventLoopGroup worker = new NioEventLoopGroup();

        try {
            ServerBootstrap boot = new ServerBootstrap();

            boot.group(boos, worker);

            boot.channel(NioServerSocketChannel.class);

            boot.childHandler(new InitChannel());

            ChannelFuture future = boot.bind(9922).sync();

            future.channel().closeFuture().sync();

        } finally {
            boos.shutdownGracefully();
            worker.shutdownGracefully();
        }
    }
}
